package com.dq.domain.annex;

import com.dq.vo.baseVo.VO;
import com.dq.domain.activity.Activity;
import com.dq.domain.category.Category;

import com.dq.domain.goods.Goods;
import com.dq.domain.org.Org;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @author liuhui
 * @date 2019/9/11 15:50
 */
@Data
@Entity
@ApiModel("附件")
public class MallAnnex extends SysAnnex implements VO.ToVO {
    @ManyToOne
    @ApiModelProperty(value = "商品", hidden = true)
    protected Goods goods;
    @ManyToOne
    @ApiModelProperty(value = "分类", hidden = true)
    protected Category category;
    @ManyToOne
    @ApiModelProperty(value = "店铺", hidden = true)
    protected Org org;
    @ManyToOne
    @ApiModelProperty(value = "活动", hidden = true)
    protected Activity activity;

    @Data
    @ApiModel(value = "附件视图")
    public static class Vo implements VO {
        @ApiModelProperty(value = "附件id")
        private Long annexId;
        @ApiModelProperty(value = "附件编号")
        private String annexNo;
        @ApiModelProperty(value = "附件名称")
        private String name;
        @ApiModelProperty(value = "附件排序")
        private Long sortNo;
        @ApiModelProperty(value = "附件目标链接")
        private String targetAddressUrl;
        @ApiModelProperty(value = "显示地址")
        private String url;
        @ApiModelProperty(value = "用户id")
        private Long userId;
        @ApiModelProperty(value = "商品id")
        private Long goodId;
        @ApiModelProperty(value = "分类id")
        private Long categoryId;
        @ApiModelProperty(value = "活动id")
        private Long activityId;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.annexId = this.id;
        vo.annexNo = this.getAnnexNo();
        vo.name = this.getName();
        vo.sortNo = this.getSortNo();
        vo.targetAddressUrl = this.getTargetAddressUrl();
        vo.url = this.getShowUrl();
        vo.userId = this.getSysUser() == null ? null : this.getSysUser().getId();
        vo.goodId = this.getGoods() == null ? null : this.getGoods().getId();
        vo.categoryId = this.getCategory() == null ? null : this.getCategory().getId();
        vo.activityId = this.getActivity() == null ? null : this.getActivity().getId();
        return vo;
    }
}
